# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=json
_pkgname=nlohmann-json
pkgbase=mingw-w64-${_pkgname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_pkgname}"
pkgver=3.8.0
pkgrel=1
pkgdesc="JSON for Modern C++ (mingw-w64)"
arch=('any')
url="https://github.com/nlohmann/json"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
conflicts=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
provides=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
replaces=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
options=('staticlibs' '!strip' '!buildflags')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/nlohmann/json/archive/v${pkgver}.tar.gz")
sha256sums=('7d0edf65f2ac7390af5e5a0b323b31202a6c11d744a74b588dc30f5a8c9865ba')

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DJSON_BuildTests=ON \
    -DJSON_Install=ON \
    ../${_realname}-${pkgver}

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make DESTDIR=${pkgdir} install
}
